{include file="common/head"/}
<div class="layui-fluid"><div class="layui-card"><div class="layui-card-body">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{:lang('module')}{:lang('list')}</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        <a href="{:url('add')}" class="layui-btn layui-btn-small">{:lang('add')}{:lang('module')}</a>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
</div>
</div>
{include file="common/foot"/}
<script type="text/html" id="action">
    <a href="{:url('field')}?id={{d.id}}" class="layui-btn layui-btn-normal layui-btn-mini">模型字段</a>
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-mini">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">{:lang('del')}</a>
</script>
<script type="text/html" id="status">
    {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-mini layui-btn-warm" lay-event="status">开启</a>
    {{# }else{  }}
    <a class="layui-btn layui-btn-mini layui-btn-danger" lay-event="status">禁用</a>
    {{# } }}
</script>
<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page:true,
            cols: [[
                {field: 'id', title: '{:lang("id")}', width:60, fixed: true},
                {field: 'title', title: '{:lang("module")}{:lang("name")}', width: 120},
                {field: 'name', title: '{:lang("table")}', width: 100},
                {field: 'description', title: '{:lang("detail")}', width: 180},
                {field: 'status', align: 'center',title: '{:lang("status")}', width: 80,toolbar: '#status'},
                {width: 200, align: 'center', toolbar: '#action'}
            ]]
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'status') {
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post('{:url("moduleState")}', {'id': data.id}, function (res) {
                    layer.close(loading);
                    if (res.status == 1) {
                        if (res.moduleState == 1) {
                            obj.update({
                                status: '<a class="layui-btn layui-btn-warm layui-btn-mini" lay-event="status">开启</a>'
                            });
                        } else {
                            obj.update({
                                status: '<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="status">禁用</a>'
                            });
                        }
                    } else {
                        layer.msg('操作失败！', {time: 1000, icon: 2});
                        return false;
                    }
                })
            }else if(obj.event === 'del'){
                layer.confirm('你确定要删除该模型吗？', {icon: 3}, function (index) {
                    $.post("{:url('del')}",{id:data.id},function(res){
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    })
</script>